define(function(require){
    var main =require('/static/main.js');
    var m = new main();
    function Cont(){
        this.Fun._init();
    }
    Cont.prototype.Fun = {
        _init:function(){
            this.getlist();
            this.bindEvent();
        },
        bindEvent:function(){
            // 编辑
            $(document).on('click','.Edit',function(){
                var id = $(this).attr('data-id');
                window.location.href = '/enterpriseplatform/add?entcode='+id;
            })
              //企业员工 列表
            $(document).on('click','.Employee',function(){
                var id = $(this).attr('data-id');
                window.location.href = '/enterpriseplatform/employee?entcode='+id;
            })

        },
        getlist:function(){
            var param = {};
            var sort = 0;
            var table = $('#datatable').dataTable({
                'ordering':false,
                "serverSide": true,
                "searching":false,
                'bLengthChange': false,
                'bPaginate': true,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                ajax: function (data, callback, settings) {
                    //封装请求参数
                    param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.PageNo = (data.start / data.length)+1;//当前页码
                    sort = (param.PageNo-1)*param.PageSize;
                    //ajax请求数据
                    $.ajax({
                        type: "POST",
                        url: "/enterpriseplatform/get-enterprise-list",
                        cache: false,  //禁用缓存
                        data: param,  //传入组装的参数
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
                        }
                    });
                },
                "aoColumns":[
                    { "mDataProp": 'ENTCode'},
                    {
                        "mDataProp": 'ENTLogo',
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<img style="with:60px;height:40px;" src="'+oData.ImgHost +oData.ENTLogo +'" onerror="this.src=\'/modules/img/default.jpg\'"/>');

                        }
                    },
                    {"mDataProp": 'ENTName'},
                    {"mDataProp": 'ShortName'},
                    {"mDataProp": 'CallName'},
                    {"mDataProp": 'CallPhone'},
                    {"mDataProp": 'ComIndustry',
                        render:function(data){
                            var ComIndustry = '';
                            switch(data){
                                case 100:ComIndustry = '计算机/互联网'; break;
                                case 110:ComIndustry = '日用杂货/家电'; break;
                                case 120:ComIndustry = '商业服务'; break;
                                case 130:ComIndustry = '工业/工业品'; break;
                                case 140:ComIndustry = '金融/保险'; break;
                                case 150:ComIndustry = '教育/出国'; break;
                                case 160:ComIndustry = '生活服务'; break;
                                case 170:ComIndustry = '鞋服/工艺品/奢侈品'; break;
                                case 180:ComIndustry = '媒体/广告/出版'; break;
                                case 190:ComIndustry = '房产/装修/租售'; break;
                                case 200:ComIndustry = '医疗/整形整容'; break;
                                case 210:ComIndustry = '美食餐饮'; break;
                                case 220:ComIndustry = '旅行/出行'; break;
                                case 230:ComIndustry = '美容/保健'; break;
                                case 240:ComIndustry = '手机机数码/通讯服务'; break;
                                case 250:ComIndustry = '汽车/汽配/租赁'; break;
                                case 260:ComIndustry = '休闲娱乐'; break;
                                case 270:ComIndustry = '政府机关/社会组织'; break;

                            }
                        return ComIndustry;
                        }
                    },
                    {"mDataProp": 'AuditStatusName',
                        //render:function(data){
                        //    var CompanyScale = '';
                        //    switch(data){
                        //        case 1:CompanyScale = '0-300万'; break;
                        //        case 2:CompanyScale = '300万-1000万'; break;
                        //        case 3:CompanyScale = '1000万-3000万'; break;
                        //        case 4:CompanyScale = '3000万-5000万'; break;
                        //        case 5:CompanyScale = '1亿+'; break;
                        //    }
                        //    return CompanyScale;
                        //}
                    },
                    {"mDataProp": 'ExpireDate',
                        render:function(data){
                            return m.formatYmd(data);
                        }
                    },
                    {"mDataProp": 'ENTSourceName'},
                    {"mDataProp": 'CreateTime',
                        render:function(data){
                            return m.formatTimeAll2(data);
                        }
                    },
                    {
                        "mDataProp": "ENTCode",
                        "sClass": "option_btn",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            // console.log(arguments);
                            $(nTd).html('<span class="btn_detial Edit" data-id="'+sData+'">编辑</span>\
                                            <span class="btn_del DelBtn"  data-id="'+sData+'">删除</span>\
                                            <span class="btn_detial Employee"  data-id="'+sData+'">企业员工列表</span>');
                        }
                    }
                ]
            }).api();

            // 点击搜索
            $('#btnSearch').click(function(){
                param.ENTCode = $('.ENTCode').val();
                param.ENTName = $('.ENTName').val();
                var table = $('#datatable').DataTable();
                table.ajax.reload();

            });
            // 点击重置按钮
            $('#btnRefresh').click(function(){
                $('.ENTCode').val('');
                $('.ENTName').val('');
                param.ENTCode = '';
                param.ENTName = '';
                var table = $('#datatable').DataTable();
                table.ajax.reload();
            });
            // 删除
            var isactive = false;
            $(document).on('click','.DelBtn',function(){
                if(isactive == true){
                    return false;
                }
                var id = $(this).attr('data-id');
                layer.confirm('确认删除该企业吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    isactive = true;
                    $.ajax({
                        type: "POST",
                        url: "/enterpriseplatform/enterprise-delete",
                        data :{ENTCode:id},
                        dataType: "json",
                        success: function (ret){
                            isactive = false;
                            if(ret.IsBizSuccess){
                                layer.msg("删除成功");
                                var table1 = $('#datatable').DataTable();
                                table1.ajax.reload();
                            }else{
                                layer.msg(ret.ErrMsg);
                            }
                        }
                    });


                });

            });


        }
    }
    var a = new Cont();

})